package m3f.interact;

import m3f.data.MultimodalCachedLoader;
import m3f.data.SingleDataSet;
import m3f.retrieval.BackProjectedRank;
import m3f.retrieval.Rank;

public class RankingBackprojection {

	public static void run(String[] args) {
		if(args.length < 6){
			System.out.println("Parameters:\n" +
					"\t1 Database visual file\n" +
					"\t2 Queries visual file\n" +
					"\t3 P\n" +
					"\t4 H\n" +
					"\t5 U\n" +
					"\t6 Alpha\n" +
					"\t7 Beta\n" +
					"\t8 Database names\n" +
					"\t9 Queries names\n" +
					"\t10 Trec output file\n" +
					"\t11 Similarity Measure\n" +
					"\t[12 Max Results]\n" +
					"\t[13 Combined Queries file]\n" +
					"\t[14 Operator]\n");
			System.exit(0);
		}
		
		String dbFile = args[1];
		String qrFile = args[2];
		String pFile = args[3];
		String hFile = args[4];
		String uFile = args[5];
		double alpha = Double.parseDouble(args[6]);
		double beta = Double.parseDouble(args[7]);
		String dbFileNames = args[8];
		String qFileNames = args[9];
		String trecOutputFile = args[10];
		Rank.SimilarityMeasure measure = Rank.SimilarityMeasure.valueOf(args[11]);
		
		MultimodalCachedLoader trainingSet = new MultimodalCachedLoader(dbFile, hFile, false);
		SingleDataSet testSet = new SingleDataSet(qrFile, false);
		SingleDataSet P = new SingleDataSet(pFile, false);
		SingleDataSet u = new SingleDataSet(uFile, false);
		
		BackProjectedRank bpr = new BackProjectedRank(trainingSet, testSet, u, P, alpha, beta, dbFileNames, qFileNames, measure);
		
		int maxResults = trainingSet.matrixRows();
		if (args.length > 12 ) {
			maxResults = Integer.parseInt(args[12]);
		}
		if (args.length > 13) {
			String combinedQeuriesFile = args[13];
			Rank.Operator operator = Rank.Operator.avg;
			if (args.length > 14) {
				operator = Rank.Operator.valueOf(args[14]);
			}
			bpr.ranking(combinedQeuriesFile, operator);
		} else {
			bpr.ranking();
		}
		bpr.writeTrecEvalTopFile(trecOutputFile, maxResults);		
	}

}
